package mamma.dao;

import java.util.List;

import mamma.common.MybatisConfig;
import mamma.vo.BannerVo;
import mamma.vo.InformationVo;
//import mamma.vo.jusaVO;


import mamma.vo.MemberVo;
import mamma.vo.VaccinationVo;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;



public class AdminDao {
	private SqlSessionFactory factory;
	
	public AdminDao(){
		factory = MybatisConfig.getSqlSessionFactory();
	}
	
	
	public void nwrite(InformationVo info) {
		System.out.println("아아. 여기는 DAO입니다.");
		SqlSession ss = null;
		try {
			ss = factory.openSession();
			ss.insert("admin.insert", info);
			ss.commit();
		} catch (Exception e) {			
			e.printStackTrace();
		} finally {
			if (ss != null)
				ss.close();
		}

	}
	
	public List<InformationVo> list(String adminId){
		List<InformationVo> list = null;
		SqlSession ss = null;
		try {
			ss = factory.openSession();
			list= ss.selectList("admin.selectList",adminId);
			ss.commit();
		} catch (Exception e) {			
			e.printStackTrace();
		} finally {
			if (ss != null)
				ss.close();
		}
		return list;
	}
	
	public InformationVo read(int id) {
		SqlSession ss = null;
		InformationVo vo =null;
		try {
			ss = factory.openSession();
			vo = ss.selectOne("admin.select", id);
			ss.commit();
		} catch (Exception e) {			
			e.printStackTrace();
		} finally {
			if (ss != null)
				ss.close();
		}
		return vo;

	}
	
	public void update(InformationVo info) {
		System.out.println("아아. 여기는 DAO입니다.");
		SqlSession ss = null;
		try {
			ss = factory.openSession();
			ss.update("admin.update", info);
			ss.commit();
		} catch (Exception e) {			
			e.printStackTrace();
		} finally {
			if (ss != null)
				ss.close();
		}

	}
	
	public int ndelete(int id) {
		SqlSession ss = null;
		
		try {
			ss = factory.openSession();
			ss.delete("admin.delete", id);
			ss.commit();
		} catch (Exception e) {			
			e.printStackTrace();
		} finally {
			if (ss != null)
				ss.close();
		}
		return id;
		
	}
	
	public void jusa(VaccinationVo jusa) {
		System.out.println("아아. 여기는 주사 DAO입니다.");
		SqlSession ss = null;
		try {
			ss = factory.openSession();
			ss.insert("admin.insert1", jusa);
			ss.commit();
		} catch (Exception e) {			
			e.printStackTrace();
		} finally {
			if (ss != null)
				ss.close();
		}

	}
	
	public List<VaccinationVo> jlist(){
		List<VaccinationVo> jlist = null;
		SqlSession ss = null;
		try {
			ss = factory.openSession();
			jlist= ss.selectList("admin.selectList1");
			ss.commit();
		} catch (Exception e) {			
			e.printStackTrace();
		} finally {
			if (ss != null)
				ss.close();
		}
		return jlist;
	}
	
	public VaccinationVo jread(int id) {
		SqlSession ss = null;
		VaccinationVo vo =null;
		try {
			ss = factory.openSession();
			vo = ss.selectOne("admin.select1", id);
			ss.commit();
		} catch (Exception e) {			
			e.printStackTrace();
		} finally {
			if (ss != null)
				ss.close();
		}
		return vo;

	}
	
	public void jupdate(VaccinationVo jusa) {
		System.out.println("아아. 여기는 DAO입니다.");
		System.out.println(jusa);
		System.out.println("주사확인했나여?");
		SqlSession ss = null;
		try {
			ss = factory.openSession();
			ss.update("admin.update1", jusa);
			ss.commit();
		} catch (Exception e) {			
			e.printStackTrace();
		} finally {
			if (ss != null)
				ss.close();
		}

	}
	
	public int jdelete(int id) {
		SqlSession ss = null;
		
		try {
			ss = factory.openSession();
			ss.delete("admin.delete1", id);
			ss.commit();
		} catch (Exception e) {			
			e.printStackTrace();
		} finally {
			if (ss != null)
				ss.close();
		}
		return id;
		
	}
	
	public List<MemberVo> mlist(){
		List<MemberVo> mlist = null;
		SqlSession ss = null;
		try {
			ss = factory.openSession();
			mlist= ss.selectList("admin.selectList2");
			ss.commit();
		} catch (Exception e) {			
			e.printStackTrace();
		} finally {
			if (ss != null)
				ss.close();
		}
		return mlist;
	}
	
	public String mdelete(String email) {
		SqlSession ss = null;
		
		try {
			ss = factory.openSession();
			ss.delete("admin.delete2", email);
			ss.commit();
		} catch (Exception e) {			
			e.printStackTrace();
		} finally {
			if (ss != null)
				ss.close();
		}
		return email;
		
	}
	
	public void insertbanner(BannerVo banner) {
		System.out.println("아아. 여기는 DAO입니다.");
		SqlSession ss = null;
		try {
			ss = factory.openSession();
			ss.update("admin.updatebanner", banner);
			ss.commit();
		} catch (Exception e) {			
			e.printStackTrace();
		} finally {
			if (ss != null)
				ss.close();
		}

	}
	
	public void bade(BannerVo banner) {
		System.out.println("아아. 여기는 DAO입니다.");
		SqlSession ss = null;
		try {
			ss = factory.openSession();
			ss.update("admin.updatebanner1", banner);
			ss.commit();
		} catch (Exception e) {			
			e.printStackTrace();
		} finally {
			if (ss != null)
				ss.close();
		}

	}
	
	public BannerVo baget(int id) {
		SqlSession ss = null;
		BannerVo vo =null;
		try {
			ss = factory.openSession();
			vo = ss.selectOne("admin.baselect", id);
			ss.commit();
		} catch (Exception e) {			
			e.printStackTrace();
		} finally {
			if (ss != null)
				ss.close();
		}
		return vo;

	}
	
	public List<VaccinationVo> selectVac(String email){
		SqlSession session = factory.openSession();
		List<VaccinationVo> list = session.selectList("admin.selectVac", email);
		session.close();
		
		return list;
	}
	
}
